home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / QuickDraw / MakeIcon / MakeIcon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  2.7 KB  |  120 lines  |  [TEXT/KAHL]

  1. #include <QDOffScreen.h>
  2. #include "IconUtil.h"
  3.  
  4. #define ICONID 128
  5.  
  6.  
  7. /* this program shows how to take any size pixmap and scale it down to any size or depth icon. */
  8. /*    By Brigham Stevens
  9.     2-6-92
  10.     Apple Computer Developer Technical Support
  11. */
  12.  
  13. main()
  14. {
  15.  
  16.     CWindowPtr    cwp;
  17.     Handle        icon;
  18.     Handle        iconMask;
  19.     GWorldPtr    gwp;
  20.     Handle        h;
  21.     Rect        demo;
  22.     short        ref,err;
  23.     long        iconSize;
  24.     
  25.     
  26.     InitToolBox(4);                    // Witch Chant + 4 calls to More Masters
  27.     
  28.     /* load map of earth in color - no hilite palette */
  29.     cwp = GetNewCWindow(128,NIL,(void*)-1L);
  30.     gwp = LoadPictToGWorld(128, cwp, 256, 8, 8, true);    
  31.     SetWTitle(cwp,"\pFlailing about rapidly contorting");
  32.     ShowWindow(cwp);
  33.     DrawImage(cwp);
  34.  
  35.     while(!Button());                    // after a click then we make a small icon thang....
  36.     FlushEvents(everyEvent,0);
  37.     SetRect(&demo,100,100,132,132);        // this is the area of pixmap we make icon from
  38.                                         // it can be the entire portRect if we want
  39.     
  40.     
  41.     
  42.     ref = OpenResFile("\pMakeIcon.output");        // THIS FILE MUST EXIST, or we may croak
  43.     if(ResError())    ExitToShell();
  44.     
  45.     icon = MakeIcon(gwp,&demo,1,32);            // make 32x32 1-bit color icon
  46.     
  47.     if(icon)
  48.     {
  49.         TryRemoveResource('ICON',ICONID);
  50.         AddResource( icon, 'ICON', ICONID, "\p");
  51.         CheckError("\pAddResFail ICON",ResError());
  52.     }
  53.  
  54.     icon = MakeIcon(gwp,&demo,1,16);            // make 16x16 1-bit color icon
  55.     
  56.     if(icon)
  57.     {
  58.         TryRemoveResource('SICN',ICONID);
  59.         AddResource( icon, 'SICN', ICONID, "\p");
  60.         CheckError("\pAddResFail SICN",ResError());
  61.     }
  62.  
  63.     icon =    MakeICN_pound(gwp, &demo, 32);        // create 32x32 1-bit color icon AND MASK
  64.     if(icon)
  65.     {
  66.         TryRemoveResource('ICN#',ICONID);
  67.         AddResource( icon, 'ICN#', ICONID, "\p");
  68.         CheckError("\pAddResFail ICN#",ResError());
  69.     }
  70.  
  71.     icon =    MakeICN_pound(gwp, &demo, 16);        // create 16x16 1-bit color icon AND MASK
  72.     if(icon)
  73.     {
  74.         TryRemoveResource('ics#',ICONID);
  75.         AddResource( icon, 'ics#', ICONID, "\p");
  76.         CheckError("\pAddResFail ics#",ResError());
  77.     }
  78.  
  79.     icon = MakeIcon(gwp,&demo,8,32);            // make 32x32 8-bit color icon
  80.     
  81.     if(icon)
  82.     {
  83.         TryRemoveResource('icl8',ICONID);
  84.         AddResource( icon, 'icl8', ICONID, "\p");
  85.         CheckError("\pAddResFail icl8",ResError());
  86.     }
  87.  
  88.     icon = MakeIcon(gwp,&demo,4,32);            // make 32x32 4-bit color icon
  89.     
  90.     if(icon)
  91.     {
  92.         TryRemoveResource('icl4',ICONID);
  93.         AddResource( icon, 'icl4', ICONID, "\p");
  94.         CheckError("\pAddResFail icl4",ResError());
  95.     }
  96.  
  97.  
  98.     icon = MakeIcon(gwp,&demo,8,16);                // make 16x16 8-bit color mask
  99.     
  100.     if(icon)
  101.     {
  102.         TryRemoveResource('ics8',ICONID);
  103.         AddResource( icon, 'ics8', ICONID, "\p");
  104.         CheckError("\pAddResFail ics8",ResError());
  105.     }
  106.  
  107.     icon = MakeIcon(gwp,&demo,4,16);                // make 16x16 4-bit color mask
  108.     
  109.     if(icon)
  110.     {
  111.         TryRemoveResource('ics4',ICONID);
  112.         AddResource( icon, 'ics4', ICONID, "\p");
  113.         CheckError("\pAddResFail ics4",ResError());
  114.     }
  115.  
  116.     CloseResFile(ref);
  117. }
  118.  
  119.  
  120.